<template>
  <div style="display: flex;" v-show="showNowStatus" :class="getUserStatusClass()">
    <div class="userStatusLeft">
      <div class="mainTel">{{mainTel}}</div>
      <!-- 用户信息 -->
      <div class="userInfo" v-if="talkArr[0]">
        <div class="info-head">用户信息</div>
        <div>姓名:{{talkArr[0].realName}}</div>
        <div>号码:{{talkArr[0].defaultNo}}</div>
        <div>性别:{{talkArr[0].sex == 1?'男':'女'}}</div>
        <div>职务:{{talkArr[0].myDutyName}}</div>
        <div>部门:{{talkArr[0].groupName}}</div>
        <div>备注:{{talkArr[0].remark}}</div>
      </div>
      <!-- 地图 -->
      <div class="mapInfo" v-show="showGis">
        <div style="height:180px;width: 90%;">
          <div id="allmap" style="width:100%;height:100%;"></div>
        </div>
      </div>
    </div>
    <div class="userStatusRight">
      <div v-show="isVideoStatus" style="height:100%">
        <div class="talkVideoDiv">
          <!-- 对方画面 -->
          <video class="video" id="remoteVideo" autoplay></video>
          <!-- 本人画面 -->
          <div class="videoLocalDiv">
            <video class="videoDiv" muted id="videoLocal" autoplay></video>
          </div>
        </div>
        <div style="position:absolute;bottom:10px;width:85%">
          <el-button
            v-show="isVideoStatus"
            type="danger"
            class="dangerButton"
            align="center"
            @click="handleClearVideoCall"
          >挂断</el-button>
          <img src="../../assets/images/shouqi.png" class="img" @click="getNowStatusDiv('close')" />
        </div>
      </div>
      <!--  -->
      <div v-show="!isVideoStatus">
        <div class="userStatustalkTop" align="center">
          <div v-if="talkArr[0]">{{ talkArr[0].defaultNo }} {{talkArr[0].realName}}</div>
          <div v-if="talkArr[0]">{{ talkArr[0].groupName }}</div>
        </div>
        <div class="userStatustalkCenter" align="center">
          {{ callStatus[telStatus] && callStatus[telStatus].text
          ? callStatus[telStatus].text
          : '空闲' }}
          <span
            v-if="talkArr[0]"
          >{{talkArr[0].talkTime}}</span>
        </div>
        <div style="height:200px">
          <img src="../../assets/images/idle.png" class="userStatusImg" />
        </div>
        <div class="userStatusBottom">
          <div v-show="!isVideoStatus" align="center" style="font-size:19px;">本地终端</div>
          <el-button
            v-if="telStatus=='broadcast'"
            type="danger"
            class="dangerButton"
            align="center"
            @click="handleStopByIsCheck"
          >挂断</el-button>
          <el-button
            v-if="telStatus=='hold'"
            type="danger"
            class="dangerButton"
            align="center"
            @click="handleStopHold"
          >挂断</el-button>
          <img src="../../assets/images/shouqi.png" class="img" @click="getNowStatusDiv('close')" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
export default {
  props: {
    isVideoStatus: Boolean,
    showNowStatus: Boolean,
    linkDevice: String,
    telStatus: String,
    talkArr: Array,
    isClassBig: Boolean,
    mainTel: String,
  },
  components: {},
  data() {
    return {
      callStatus: {
        idle: { text: '', pic: require('../../assets/images/idle.png') },
        ready: {
          text: '准备呼出',
          pic: require('../../assets/images/ready.png'),
        },
        callin: {
          text: '呼叫中',
          pic: require('../../assets/images/ring.png'),
        },
        ring: { text: '振铃', pic: require('../../assets/images/ring.png') },
        talk: { text: '通话中', pic: require('../../assets/images/talk.png') },
        broadcast: {
          text: '广播中',
          pic: require('../../assets/images/Broadcast.png'),
        },
        hold: { text: '保持', pic: require('../../assets/images/hold.png') },
        queue: {
          text: '排队中',
          pic: require('../../assets/images/queue.png'),
        },
        callfail: {
          text: '呼叫失败',
          pic: require('../../assets/images/callfail.png'),
        },
        allowspeak: {
          // text: '自由发言',
          text: '会议中',
          pic: require('../../assets/images/allowspeak.png'),
        },
        banspeak: {
          // text: '禁止发言',
          text: '会议中',
          pic: require('../../assets/images/banspeak.png'),
        },
        singletalk: {
          text: '单独通话',
          pic: require('../../assets/images/singletalk.png'),
        },
        offline: {
          text: '离线',
          pic: require('../../assets/images/offline.png'),
        },
        monitorring: {
          text: '监测振铃',
          pic: require('../../assets/images/monitorring.png'),
        },
        monitortalk: {
          text: '监测通话',
          pic: require('../../assets/images/monitortalk.png'),
        },
      },
      userInfo: {},
      showGis: false,
    }
  },
  computed: mapState({
    deviceStatusMap: (state) => state.cache.deviceStatusMap,
    groupMap: (state) => state.cache.groupMap,
    telOperatorMap: (state) => state.cache.telOperatorMap,
    telEmployeeMap: (state) => state.cache.telEmployeeMap,
    gpsBHMap: (state) => state.cache.gpsBHMap,
  }),

  watch: {
    isVideoStatus(n, o) {
      //n为新值,o为旧值;
      console.log('4444444444')
      this.isVideoStatus = n
      console.log(this.isVideoStatus)
      this.$forceUpdate()
    },
    talkArr: {
      handler(newValue, oldValue) {
        for (let i = 0; i < newValue.length; i++) {
          if (oldValue[i] != newValue[i]) {
          }
        }
      },
      deep: true,
    },
  },

  methods: {
    //初始化
    init() {},
    //关闭
    getNowStatusDiv(type) {
      this.$emit('getNowStatusDiv', type)
    },
    //视频挂断
    handleClearVideoCall() {
      // this.$emit('update:isVideoStatus', false)
      this.$emit('handleClearVideoCall')
    },
    //广播挂断
    handleStopByIsCheck() {
      this.$emit('handleStopByIsCheck')
    },
    //保持状态的挂断
    handleStopHold() {
      this.$emit('handleStopHold')
    },
    //获取样式
    getUserStatusClass() {
      return this.isClassBig ? 'showNowStatusClassBig' : 'showNowStatusClass'
    },
    //显示地图
    handleShowGis() {
      this.showGis = false
      if (this.talkArr.length > 0) {
        let emp = this.talkArr[0]
        if (
          emp != undefined &&
          emp.pos_x != '' &&
          emp.pos_y != '' &&
          emp.pos_x != null &&
          emp.pos_y != null
        ) {
          this.showGis = true
        }
        setTimeout(() => {
          this.initBmap('allmap', emp)
        }, 100)
      }
    },
    /*
     *初始化地图
     *@parma 地图id
     *@parma 经纬度信息
     */
    initBmap(id, row) {
      let _this = this
      let map = (this.map = new BMap.Map(id, {
        minZoom: 4,
        maxZoom: 19,
        enableMapClick: false,
      })) // 创建Map实例
      let centerAndZoom = bmapConfig.centerAndZoom
      //添加标注
      if (
        row != undefined &&
        row.pos_x != '' &&
        row.pos_y != '' &&
        row.pos_x != null &&
        row.pos_y != null
      ) {
        var point = new BMap.Point(row.pos_x, row.pos_y)
        map.centerAndZoom(point, 13)
        var marker = new BMap.Marker(point) // 创建标注
        map.addOverlay(marker)
      } else {
        // 初始化地图,设置中心点坐标和地图级别
        //新增进入
        map.centerAndZoom(
          new BMap.Point(centerAndZoom.lng, centerAndZoom.lat),
          centerAndZoom.zoom
        )
      }
      //启用滚轮放大缩小
      map.enableScrollWheelZoom()
    },
  },
  mounted() {
    this.init()
  },
}
</script>

<style lang="scss" scoped>
.showNowStatusClass {
  border-bottom: 5px solid #f2f2f2;
  border-left: 4px solid #f2f2f2;
  border-right: 4px solid #f2f2f2;
  border-top: 4px solid #f2f2f2;
  height: calc(100% - 130px);
  width: calc(100%);
  float: left;
  position: relative;
  z-index: 2000;
}
.showNowStatusClassBig {
  border-bottom: 5px solid #f2f2f2;
  border-left: 4px solid #f2f2f2;
  border-right: 4px solid #f2f2f2;
  border-top: 4px solid #f2f2f2;
  height: calc(100% - 130px);
  width: calc(100% + 200px);
  float: left;
  position: relative;
  z-index: 2000;
}
.userStatusLeft {
  width: 15%;
  background-color: #f2f2f2;
  .mainTel {
    height: 50px;
    width: 97%;
    background-color: white;
    text-align: center;
    line-height: 50px;
    color: #6bb5e6;
    font-size: 23px;
  }
  .userInfo {
    border: 1px solid #aaaaaa;
    margin: 10px;
    padding: 10px 10px;
    .info-head {
      text-align: center;
      font-size: 18px;
    }
  }
  .mapInfo {
    border: 1px solid #aaaaaa;
    margin: 10px;
    // padding: 10px 10px;
  }
}
.userStatusRight {
  height: 100%;
  width: 85%;
}
.userStatustalkTop {
  font-size: 28px;
  height: 150px;
  line-height: 60px;
}
.userStatustalkCenter {
  font-size: 35px;
}
.userStatusImg {
  margin-left: 46%;
  margin-top: 150px;
  border-radius: 100%;
  width: 8%;
}
.userStatusBottom {
  position: absolute;
  bottom: 0px;
  width: 85%;
}
.dangerButton {
  margin-left: 48%;
  margin-top: 1%;
}
.img {
  width: 60px;
  float: right;
}
.talkVideoDiv {
  height: calc(100% - 70px);
  width: 100%;
}
.video {
  width: 100%;
  object-fit: fill;
  height: 100%;
}
.videoDiv {
  width: 100%;
  height: 100%;
  object-fit: fill;
}
.videoLocalDiv {
  position: absolute;
  right: 0;
  bottom: 70px;
  width: 20%;
  height: 20%;
  object-fit: fill;
}
@media screen and (max-width: 1440px) and (min-width: 1024px) {
  .userStatustalkTop {
    font-size: 18px;
    height: 65px;
    line-height: 35px;
  }
  .userStatusImg {
    margin-top: 26px;
  }
  .showNowStatusClass {
    height: calc(100% - 110px);
  }
  .showNowStatusClassBig {
    height: calc(100% - 110px);
  }
}
@media screen and (max-width: 1024px) {
  .showNowStatusClass {
    height: calc(100% - 85px);
    width: calc(100%);
  }
  .showNowStatusClassBig {
    width: calc(100% + 170px);
    height: calc(100% - 80px);
  }
  .userStatustalkTop {
    font-size: 18px;
    height: 75px;
    line-height: 35px;
  }
  .userStatustalkCenter {
    font-size: 25px;
  }
  .userStatusImg {
    margin-top: 10px;
  }
  .img {
    width: 40px;
  }
  .userStatusLeft {
    .mainTel {
      font-size: 18px;
    }
  }
  .talkVideoDiv {
    height: calc(100% - 60px);
    width: 100%;
  }
  .video {
    height: 100%;
    object-fit: fill;
    width: 100%;
  }
  .videoLocalDiv {
    position: absolute;
    right: 0;
    bottom: 60px;
    width: 20%;
    height: 20%;
    object-fit: fill;
  }
}
@media screen and (max-width: 1440px) and (min-width: 1024px) {
  .img {
    width: 50px;
  }
}
</style>